package com.white.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.white.bean.SearchHistory;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface SearchHistoryMapper extends BaseMapper<SearchHistory> {
    String TABLE_NAME = " SearchHistory ";
    String ORDER_BY = " order by createTime desc ";
    int LIMIT = 10;

     @Insert("insert" + TABLE_NAME + "(userId, content) values(#{userId}, #{content})")
    void create(SearchHistory searchHistory) throws Exception;

    @Select("select * from" + TABLE_NAME + "where userId = #{userId}" + ORDER_BY)
    List<SearchHistory> searchByUserId(Long userId);

    @Delete("delete from" + TABLE_NAME + "where searchHistoryId = #{searchHistoryId}")
    void deleteBySearchHistoryId(Long searchHistoryId);

    @Select("select * from" + TABLE_NAME + "where content = #{content}")
    SearchHistory selectByContent(String content);
}
